<template>
	<view class="content" :style="{ height: windowHeight + 'px' }">
		<u--form :model="model1" :rules="rules" ref="uForm" labelWidth="80">
			<u-form-item label="标题" prop="title">
				<u--input v-model="model1.title" placeholder="请输入举报投诉标题"></u--input>
			</u-form-item>
			<u-form-item label="内容" prop="content">
				<u--textarea v-model="model1.content" maxlength="-1" clearable height="160"
					placeholder="请填写原因"></u--textarea>
			</u-form-item>
			<view class="flex">
				<view class="image-title">图片</view>
				<UpLoad :fileList="model1.image" name="1" multiple :maxCount="9"
					@onChange="(value) => { model1.image = value }" :place="'图最多可以上传9张'" />
			</view>
		</u--form>
		<view class="buttons" @click="submits">
			我要投诉
		</view>
	</view>
</template>

<script>
	import UpLoad from '../../components/upLoad/index.vue'
	import {
		systemInfo
	} from '../../utils/mixin'
	import {
		getDicts,
		addFeedback
	} from '@/api/index.js'
	export default {
		components: {
			UpLoad
		},
		mixins: [systemInfo],
		data() {
			return {
				model1: {
					content: '',
					title: '',
					image: ''
				},
				rules: {
					title: [{
						type: 'string',
						required: true,
						message: '请输入标题',
						trigger: ['blur', 'change']
					}],
					content: [{
						type: 'string',
						required: true,
						message: '请输入内容',
						trigger: ['blur', 'change']
					}]
				}
			}
		},
		async onLoad() {
			// 状态栏高度
			this.getSystemInfo();

		},
		methods: {
			submits() {
				this.$refs.uForm.validate().then(async (valid) => {
					if (valid) {
						if (!this.model1.image) {
							uni.$u.toast("请上传图片")
						} else {
							this.model1.image = this.model1.image.split(',').map(item => '/' + item).join(',')
							await addFeedback(this.model1)
							uni.$u.toast("举报投诉成功")
							setTimeout(function() {
								uni.switchTab({
									url: '/pages/tabbar/mine/mine'
								})
							}, 1000);
						}
					}
				})
			},
		}
	}
</script>

<style lang="less" scoped>
	.content {
		background-color: #fff;
		width: 100%;
		box-sizing: border-box;
		padding: 40rpx;

		/deep/ .u-textarea {
			// background-color: rgb(245, 247, 250);
		}

		.buttons {
			margin: 50rpx auto 0;
			width: 300rpx;
			height: 80rpx;
			background-color: rgba(254, 0, 0);
			color: #fff;
			line-height: 80rpx;
			text-align: center;
			font-size: 36rpx;
			border-radius: 10rpx;
			letter-spacing: 20rpx;
		}

		.flex {
			display: flex;
			align-items: center;
			margin-top: 20rpx;

			.image-title {
				margin-right: 20rpx;
				width: 70rpx;
			}
		}
	}
</style>